/// @tags: MatrixTree
#include <cstdio>
#include <iostream>

using namespace std;

namespace BlueQuantum {

int const N = 2e2 + 5e1 + 5, mod = 1e4 + 7;

int n, m;

int *a[N], _a[N][N];

inline int qpow(int base, int exp) {
  int res = 1;
  while (exp) {
    if (exp & 1) res = res * base % mod;
    exp >>= 1;
    base = base * base % mod;
  }
  return res;
}

inline int det(int **a) {
  int ans = 1;
  for (int i = 2; i <= n; ++i) {
    for (int j = i; j <= n; ++j)
      if (a[j][i]) {
        if (j != i) ans = ans ? mod - ans : ans, swap(a[j], a[i]);
        break;
      }
    if (a[i][i] == 0) return 0;
    ans = ans * a[i][i] % mod;
    int t = qpow(a[i][i], mod - 2);
    for (int j = i; j <= n; ++j) a[i][j] = t * a[i][j] % mod;
    for (int j = i + 1; j <= n; ++j) {
      t = mod - a[j][i];
      for (int k = i; k <= n; ++k) a[j][k] = (a[j][k] + t * a[i][k] % mod) % mod;
    }
  }
  return ans;
}

inline int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) a[i] = _a[i];
  for (int i = 1, u, v; i <= m; ++i) {
    cin >> u >> v;
    if (++a[u][u] >= mod) a[u][u] -= mod;
    if (--a[v][u] < 0) a[v][u] += mod;
  }
  cout << det(a);
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("MatrixTree.in", "r", stdin);
  freopen("MatrixTree.out", "w", stdout);
#endif
#endif

  ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
